package net.adetech.crj.service;

import net.adetech.crj.dao.AppointmentMapper;
import net.adetech.crj.entity.Appointment;
import net.adetech.crj.entity.User;
import net.adetech.crj.utils.InnerServiceUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.sql.Timestamp;
import java.util.Date;
import java.util.Map;

@Service("appointment.insert")
public class InsertAppointmentService implements BaseService {
    @Autowired
    AppointmentMapper appointmentMapper;

    @Override
    public Map<String, Object> invoke(Map<String, Object> params) {
        Appointment appointment = (Appointment) params.get("appointment");
        User user = (User) params.get("user");

        if (appointment.getApplyId()!=null&&!"".equals(appointment.getApplyId()))
        {
            this.appointmentMapper.updateAppointmentStateByApplyId(appointment.getApplyId(),"4");
        }



        if (user != null) {
            appointment.setApplyUserId(user.getIdNumber());
            if (appointment.getServiceType().equals("M"))
            {
                this.appointmentMapper.updateGroupAppointmentState(user.getIdNumber(),"4");
            }
        }

        appointment.setUpdateTime(new Timestamp(new Date().getTime()));
        appointment.setCreateTime(new Timestamp(new Date().getTime()));
        appointmentMapper.insert(appointment);


        return InnerServiceUtil.buildResult("result", "ok");
    }
}
